#!/usr/bin/perl -w
#
# $Id: StatusBar.pm,v 1.23 2003/08/01 05:15:36 solovam Exp $
#
# This file is a part of gkismet
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#

#
# StatusBar class
#
package StatusBar;

use Gtk;
use Misc;
use ReusableConnObserver;
use strict;

@StatusBar::ISA = qw(ReusableConnObserver);

#
# Constructor
#
sub new
{
	my $type = shift;
	my $self = new ReusableConnObserver(@_);
	bless $self, $type;

	$self->{'statusBar'} = new Gtk::Statusbar();
	$self->{'sbContext'} = $self->{'statusBar'}->get_context_id('status line');
	$self->{'statusBar'}->show();
	$self->{'depth'} = 0;

	return $self;
}

#
# Handle an update from an observable
#
sub update
{
	my $self = shift;
	my $object = shift;
	my $data = shift;

	if($object->isa('Connection') && defined $self->{'connection'} && $self->{'connection'} eq $object)
	{
		if($data->{'changed'} eq 'status')
		{
			$self->{'statusBar'}->push($self->{'sbContext'}, $self->{'connection'}->getStatus());
			$self->{'depth'}++;
		}
		elsif($data->{'changed'} eq 'alert')
		{
			$self->{'statusBar'}->push($self->{'sbContext'}, $self->{'connection'}->getAlert()->{'text'});
			$self->{'depth'}++;
		}
	}
}

#
# Flush all accumulated data
#
sub flush
{
	my $self = shift;
	while($self->{'depth'} > 0)
	{
		$self->{'statusBar'}->pop($self->{'sbContext'});
		$self->{'depth'}--;
	}
}

#
# Get widget
#
sub getWidget
{
	my $self = shift;
	return($self->{'statusBar'});
}

1;
